#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string addStrings(string num1, string num2)
    {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        int ret, sum, val1, val2, over = 0;
        string retstr;
        while (end1 >= 0 || end2 >= 0)
        {
            val1 = 0;
            val2 = 0;
            if (end1 >= 0)
            {
                val1 = num1[end1] - '0';
                end1--;
            }
            if (end2 >= 0)
            {
                val2 = num2[end2] - '0';
                end2--;
            }

            sum = val1 + val2 + over;
            over = sum / 10;
            sum %= 10;

            retstr += (sum + '0');
        }

        if (over == 1)
            retstr += '1';
        reverse(retstr.begin(), retstr.end());

        return retstr;
    }
};


class Solution {
public:
    bool isPalindrome(string s) {
        string news;

        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] >= 'A' && s[i] <= 'Z')
                news += (s[i] + 32);
            else if (s[i] >= 'a' && s[i] <= 'z')
                news += (s[i]);
            else if (s[i] >= '0' && s[i] <= '9')
                news += s[i];
        }

        int begin = 0, end = news.size() - 1;

        while (begin <= end)
        {
            if (news[end] != news[begin])
                return false;
            end--;
            begin++;
        }
        return true;
    }
};


class Solution {
public:
    string reverseStr(string s, int k) {
        int n = s.size();
        for (int i = 0; i < n; i += 2 * k)
        {
            reverse(s.begin() + i, s.begin() + min(i + k, n));
        }
        return s;
    }
};



class Solution {
public:
    string reverseWords(string s)
    {
        int pos = 0;
        for (int i = 0; i < s.size(); i++)
        {

            while (s[i] != ' ' && i < s.size())
            {
                i++;
            }
            reverse(s.begin() + pos, s.begin() + i);
            pos = i + 1;
        }
        return s;
    }
};